package edu.upc.fib.lamsandroid.client.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class ConfirmBoxDialog {

    public interface ConfirmBoxDialogListener {
        public void onAccept();
        public void onDeny();
    }

    private final Context context;
    private final ConfirmBoxDialogListener listener;

    public ConfirmBoxDialog(Context context, ConfirmBoxDialogListener listener) {
        this.context = context;
        this.listener = listener;
    }

    public void show(String message) {
        AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.setIcon(android.R.drawable.ic_dialog_alert);
        dialog.setTitle("Confirm");
        dialog.setMessage(message);
        dialog.setCancelable(false);

        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                listener.onAccept();
            }
        });

        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                listener.onDeny();
            }
        });

        dialog.show();
    }
}
